﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("{0,-10} {1,-10} {2,-30} {3,-30}", "类型", "字节数", "最小值", "最大值");
            Console.WriteLine(new string('-', 85));

            PrintTypeInfo<sbyte>("sbyte");
            PrintTypeInfo<byte>("byte");
            PrintTypeInfo<short>("short");
            PrintTypeInfo<ushort>("ushort");
            PrintTypeInfo<int>("int");
            PrintTypeInfo<uint>("uint");
            PrintTypeInfo<long>("long");
            PrintTypeInfo<ulong>("ulong");
            PrintTypeInfo<float>("float");
            PrintTypeInfo<double>("double");
            PrintTypeInfo<decimal>("decimal");
            Console.ReadLine();
        }

        static void PrintTypeInfo<T>(string typeName) where T : struct
        {
            Type type = typeof(T);
            int size = System.Runtime.InteropServices.Marshal.SizeOf(type);
            object minValue = type.GetField("MinValue").GetValue(null);
            object maxValue = type.GetField("MaxValue").GetValue(null);

            Console.WriteLine("{0,-10} {1,-10} {2,-30} {3,-30}",
                typeName,
                size,
                minValue.ToString(),
                maxValue.ToString());
        }
    }
}
